<?php
class Db
{
	public static $db = null;
	public static $dblink = null;
	public static $curlink = null;
	private function __construct($server, $type)
	{
		self::_connect($server, $type);
	}
	
	public static function getInstance($server, $type)
	{
		if (empty(self::$db[$server][$type]) || !(self::$db[$server][$type] instanceof self)){
			$db[$server][$type] = new self($server, $type);
		}
		return $db[$server][$type];
	}
	
	public static function _connect($server, $type)
	{
		if (!isset(self::$dblink[$server][$type]) || empty(self::$dblink[$server][$type])){
			self::$dblink[$server][$type] = self::$curlink = mysql_connect(
				Config::$db[$server][$type]['host'],
				Config::$db[$server][$type]['uname'],
				Config::$db[$server][$type]['passwd']
				);
		}
		mysql_select_db(Config::$db[$server][$type]['dbname'], self::$dblink[$server][$type]);
	}
	
	public static function query($sql)
	{
		return mysql_query($sql, self::$curlink);
	}
}